package com.zb.controller;
import com.zb.entity.Shipments;
import com.zb.util.PageUtil;
import com.zb.service.ShipmentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;


@Controller
@RequestMapping("/shipments")
public class ShipmentsController {

    @Autowired
    private ShipmentsService shipmentsService;

    @RequestMapping("/search")
    @ResponseBody
    public PageUtil<Shipments> searchShipments(@RequestParam Map<String,Object> param ,
                                                                @RequestParam(required = true, defaultValue = "1") Integer index)throws Exception {
        int size = 2;
        PageUtil<Shipments> shipmentsPage  = shipmentsService.queryShipmentsPageByMap(param, index, size);
        return shipmentsPage;
    }

    @RequestMapping("/saveOrUpdateShipments")
    @ResponseBody
    public Integer saveOrUpdateShipments(Shipments shipments){
        Integer flag=0;
        try {
            if(shipments.getId()==null || shipments.getId()==0){
                flag=shipmentsService.qdtxAddShipments(shipments);
            }else{
                flag=shipmentsService.qdtxModifyShipments(shipments);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @RequestMapping("/getShipmentsById")
    @ResponseBody
    public Shipments getShipmentsById(Long id){

        Shipments shipments=null;
        try {
            shipments=shipmentsService.getShipmentsById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return shipments;
    }

    @RequestMapping("/batchRemoveShipments")
    @ResponseBody
    public Integer batchRemoveShipments(String ids){
        Integer flag=0;
        try {
            flag=shipmentsService.qdtxBatchDeleteShipments(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @RequestMapping("/removeShipmentsById")
    @ResponseBody
    public Integer removeShipmentsById(Long id){
        Integer flag=0;
        try {
            flag=shipmentsService.qdtxDeleteShipmentsById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }
}
